VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form frmProgramRight 
   BackColor       =   &H00800000&
   Caption         =   " "
   ClientHeight    =   6900
   ClientLeft      =   1350
   ClientTop       =   1290
   ClientWidth     =   9300
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   6900
   ScaleWidth      =   9300
   Begin VB.Frame Frame1 
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   5130
      Left            =   105
      TabIndex        =   5
      Top             =   1455
      Width           =   7335
      Begin VB.Frame FrameCheck 
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         Height          =   225
         Left            =   330
         TabIndex        =   7
         Top             =   240
         Visible         =   0   'False
         Width           =   1455
         Begin VB.CheckBox chkSelect 
            BackColor       =   &H00FFFFFF&
            Height          =   225
            Left            =   645
            TabIndex        =   8
            Top             =   15
            Width           =   225
         End
      End
      Begin MSDataGridLib.DataGrid grdFunction 
         Bindings        =   "frmGroupRight.frx":0000
         Height          =   5085
         Left            =   0
         TabIndex        =   6
         Top             =   0
         Width           =   7320
         _ExtentX        =   12912
         _ExtentY        =   8969
         _Version        =   393216
         HeadLines       =   1
         RowHeight       =   15
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   4
         BeginProperty Column00 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   5
               Format          =   ""
               HaveTrueFalseNull=   1
               TrueValue       =   "True"
               FalseValue      =   "False"
               NullValue       =   ""
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "Selected"
            Caption         =   "Selected"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "Caption"
            Caption         =   "Pad Name"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "Padcode"
            Caption         =   "Pad code"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               ColumnWidth     =   14.74
            EndProperty
            BeginProperty Column01 
               Alignment       =   2
            EndProperty
            BeginProperty Column02 
               ColumnWidth     =   5160.189
            EndProperty
            BeginProperty Column03 
               ColumnWidth     =   14.74
            EndProperty
         EndProperty
      End
   End
   Begin MSDataListLib.DataCombo cboUserGroup 
      Bindings        =   "frmGroupRight.frx":0015
      Height          =   315
      Left            =   2880
      TabIndex        =   4
      Top             =   960
      Width           =   3075
      _ExtentX        =   5424
      _ExtentY        =   556
      _Version        =   393216
      ListField       =   "GroupName"
      BoundColumn     =   "UserGroup"
      Text            =   ""
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      Height          =   405
      Left            =   7740
      TabIndex        =   3
      Top             =   3225
      Width           =   1365
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "Save"
      Height          =   435
      Left            =   7725
      TabIndex        =   2
      Top             =   2610
      Width           =   1410
   End
   Begin MSAdodcLib.Adodc Adodc2 
      Height          =   330
      Left            =   6540
      Top             =   630
      Visible         =   0   'False
      Width           =   2505
      _ExtentX        =   4419
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "2.UserGroup"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   6615
      Top             =   750
      Visible         =   0   'False
      Width           =   2565
      _ExtentX        =   4524
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "1.GroupFunction"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "Group"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FFFF&
      Height          =   300
      Left            =   1695
      TabIndex        =   1
      Top             =   975
      Width           =   885
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Programe Right Management"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   21.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000E&
      Height          =   630
      Left            =   990
      TabIndex        =   0
      Top             =   105
      Width           =   7155
   End
End
Attribute VB_Name = "frmProgramRight"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim OldRow As Integer, PadcodeSelect As String
Function DeleteParent(PadDelete, DeleteType)
Dim RecGroupFunction, RecCount, recChild As Recordset
Dim ParentCode, FullPad As String, CountSameParent As Integer
Set RecGroupFunction = DBconn.Execute("SELECT " & _
    " GroupFunctionTemp.Padcode, GroupFunctionTemp.Selected," & _
    " MenuPad.ParentPadCode , MenuPad.FullPadName " & _
    " FROM GroupFunctionTemp INNER JOIN    MenuPad ON    GroupFunctionTemp.Padcode = MenuPad.PadCode" & _
    " WHERE somay=" & MAYSO & "  and GroupFunctionTemp.PadCode='" & PadDelete & "'")
ParentCode = RecGroupFunction!ParentPadCode
FullPad = RecGroupFunction!FullPadName
If DeleteType = 0 Then
        'Delete all Pad  hold Fullpad string (all child pad code of Pad Delete)
        Set recChild = DBconn.Execute("SELECT " & _
            " GroupFunctionTemp.Padcode, GroupFunctionTemp.Selected," & _
            " MenuPad.ParentPadCode , MenuPad.FullPadName " & _
            " FROM GroupFunctionTemp INNER JOIN    MenuPad ON    GroupFunctionTemp.Padcode = MenuPad.PadCode" & _
            " WHERE somay=" & MAYSO & " and SELECTED=1 ORDER BY  FullPadName ")
        If Not recChild.EOF Then
            Do Until recChild!FullPadName = FullPad
                recChild.MoveNext
                If recChild.EOF Then Exit Do
            Loop
        End If
        Do While Not recChild.EOF
            If InStr(1, recChild!FullPadName, FullPad, 0) > 0 Then
                DBconn.Execute ("UPDate GroupFunctionTemp SET Selected=0 Where Padcode='" & recChild!Padcode & "'")
            Else
                Exit Do
            End If
            recChild.MoveNext
        Loop
End If
DBconn.Execute ("UPDate GroupFunctionTemp SET Selected=0 Where Padcode='" & PadDelete & "'")
If ParentCode = "" Then Exit Function
Set RecCount = DBconn.Execute("SELECT MenuPad.ParentPadCode, COUNT(GroupFunctionTemp.PadCode) As CountPadcode " & _
    " FROM GroupFunctionTemp INNER JOIN   MenuPad ON    GroupFunctionTemp.PadCode = MenuPad.PadCode " & _
    " WHERE MenuPad.ParentPadCode='" & ParentCode & "' AND Selected=1" & _
    " GROUP BY MenuPad.ParentPadCode")
If RecCount.EOF Then
    CountSameParent = 0
Else
    CountSameParent = RecCount!CountPadCode
End If
If CountSameParent > 0 Then
    Exit Function
Else
    a = DeleteParent(ParentCode, 1)
End If
End Function

Private Sub cboUserGroup_Click(Area As Integer)
If Area = 2 Then
    UpdateSelected
    FrameCheck.Visible = False
    Adodc1.Refresh
    grdFunction.Refresh
End If
End Sub

Private Sub chkSelect_MouseUp(Button As Integer, Shift As Integer, X As Single, y As Single)
If chkSelect.value = 0 Then
    a = DeleteParent(grdFunction.Columns(3).value, 0)
Else
    a = UpdateChildSelected(grdFunction.Columns(3).value, 0)
End If
Adodc1.Refresh
Adodc1.Recordset.AbsolutePosition = PadcodeSelect
grdFunction.Refresh
FrameCheck.Top = grdFunction.RowTop(grdFunction.Row) + 20
chkSelect.value = IIf(grdFunction.Columns(1).value = -1, 1, 0)
'grdFunction.Row = OldRow
End Sub

Private Sub cmdExit_Click()
Unload frmProgramRight
End Sub

Sub OpenFile()
Dim RecMenuPad As Recordset, mCaption
DBconn.Execute ("DELETE FROM GroupFunctionTemp WHERE SoMay=" & MAYSO)
Set RecMenuPad = DBconn.Execute("Select * from MenuPad order by Padcode ")
Do While Not RecMenuPad.EOF
    If InStr(1, RecMenuPad!Padcode, "iv", 0) > 0 Then
         Select Case Len(RecMenuPad!FullPadName)
            Case 2
                mCaption = RecMenuPad!Caption
            Case 6
                mCaption = "      " & RecMenuPad!Caption
            Case 11
                mCaption = "            " & RecMenuPad!Caption
            Case 17
                mCaption = "                  " & RecMenuPad!Caption
        End Select
    Else
        Select Case Len(RecMenuPad!FullPadName)
            Case 1
                mCaption = RecMenuPad!Caption
            Case 4
                mCaption = "      " & RecMenuPad!Caption
            Case 8
                mCaption = "            " & RecMenuPad!Caption
            Case 13
                mCaption = "                  " & RecMenuPad!Caption
        End Select
    End If
    DBconn.Execute ("INSERT INTO GroupFunctionTemp (Padcode,Caption,Selected,SoMay)" & _
    " SELECT Padcode,'" & mCaption & "',0," & MAYSO & " FROM MenuPad " & _
    " Where padcode='" & RecMenuPad!Padcode & "'")
    RecMenuPad.MoveNext
Loop


Adodc1.ConnectionString = ConnectString
Adodc1.ConnectionTimeout = 10
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "SELECT GroupFunctionTemp.Padcode, GroupFunctionTemp.Caption, " & _
    " GroupFunctionTemp.Selected, GroupFunctionTemp.SoMay FROM GroupFunctionTemp INNER JOIN " & _
    " MenuPad ON  GroupFunctionTemp.Padcode = MenuPad.PadCode WHERE Somay=" & MAYSO & " Order by GroupFunctionTemp.Padcode "
Adodc1.Refresh

Adodc2.ConnectionString = ConnectString
Adodc2.ConnectionTimeout = 10
Adodc2.CommandType = adCmdText
Adodc2.RecordSource = "Select * from UserGroup"
Adodc2.Refresh
End Sub
Sub UpdateSelected()
Dim RecGroupFunction As Recordset
DBconn.Execute ("UPDATE GroupFunctionTemp SET Selected=0 where  Somay=" & MAYSO)
Set RecGroupFunction = DBconn.Execute("Select * from GroupFunction WHERE UserGroup='" & cboUserGroup.BoundText & "'")
With RecGroupFunction
    Do While Not .EOF
        DBconn.Execute ("UPDATE GroupFunctionTemp SET Selected=1 where Padcode='" & !Padcode & "'" & _
        " AND Somay=" & MAYSO)
        .MoveNext
    Loop
    .Close
End With

End Sub

Private Sub cmdSave_Click()
a = UpdateChildSelected("s1", 0)
a = UpdateChildSelected("s3", 0)
a = UpdateChildSelected("s5", 0)

DBconn.Execute ("Delete from  GroupFunction where usergroup='" & cboUserGroup.BoundText & "'")
DBconn.Execute ("Insert Into GroupFunction(UserGroup,PadCode) " & _
" Select '" & cboUserGroup.BoundText & "',Padcode FROM GroupFunctionTemp " & _
" WHERE Selected=1 and somay=" & MAYSO)
MsgBox "Scuccessfull!"
End Sub

Private Sub Form_Load()
OpenFile
End Sub

Private Sub grdFunction_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
'MsgBox "Row=" & grdFunction.Row
FrameCheck.Visible = True
OldRow = grdFunction.Row
PadcodeSelect = Adodc1.Recordset.Bookmark
FrameCheck.Top = grdFunction.RowTop(grdFunction.Row) + 20
chkSelect.value = IIf(grdFunction.Columns(1).value = -1, 1, 0)
End Sub
Function UpdateChildSelected(PadSelect, UpdateType)
Dim RecGroupFunction, RecCount, recChild As Recordset
Dim ParentCode, FullPad As String, CountSameParent As Integer
Set RecGroupFunction = DBconn.Execute("SELECT " & _
    " GroupFunctionTemp.Padcode, GroupFunctionTemp.Selected," & _
    " MenuPad.ParentPadCode , MenuPad.FullPadName " & _
    " FROM GroupFunctionTemp INNER JOIN    MenuPad ON    GroupFunctionTemp.Padcode = MenuPad.PadCode" & _
    " WHERE somay=" & MAYSO & "  and GroupFunctionTemp.PadCode='" & PadSelect & "'")
ParentCode = RecGroupFunction!ParentPadCode
FullPad = RecGroupFunction!FullPadName

'Select all Pad  hold Fullpad string (all child pad code of PadSelect)
If UpdateType = 0 Then
        Set recChild = DBconn.Execute("SELECT " & _
            " GroupFunctionTemp.Padcode, GroupFunctionTemp.Selected," & _
            " MenuPad.ParentPadCode , MenuPad.FullPadName " & _
            " FROM GroupFunctionTemp INNER JOIN    MenuPad ON    GroupFunctionTemp.Padcode = MenuPad.PadCode" & _
            " WHERE somay=" & MAYSO & "  ORDER BY  FullPadName ")
        If Not recChild.EOF Then
            Do Until recChild!FullPadName = FullPad
                recChild.MoveNext
                If recChild.EOF Then Exit Do
            Loop
        End If
        Do While Not recChild.EOF
            If InStr(1, recChild!FullPadName, FullPad, 0) > 0 Then
                DBconn.Execute ("UPDate GroupFunctionTemp SET Selected=1 Where Padcode='" & recChild!Padcode & "'")
            Else
                Exit Do
            End If
            recChild.MoveNext
        Loop
End If
DBconn.Execute ("UPDate GroupFunctionTemp SET Selected=1 Where Padcode='" & PadSelect & "'")
If ParentCode = "" Then Exit Function
a = UpdateChildSelected(ParentCode, 1)

End Function

Private Sub grdFunction_Scroll(Cancel As Integer)
FrameCheck.Visible = False
End Sub
